from django.shortcuts import render

# Create your views here.
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.generics import ListAPIView

from api.filter import Limit, Compturefilter
from api.models import Compture
from api.paginations import BasicsPagination
from api.serializer import Comptureserializer
#下面包可以使用搜索功能,前者包负责搜索公能,后者包负责排序
from rest_framework.filters import SearchFilter,OrderingFilter


class ComptureAPIView(ListAPIView):

    queryset = Compture.objects.all()
    serializer_class = Comptureserializer
    #通过此参数配置过滤器
    filter_backends = [SearchFilter,OrderingFilter,Limit,DjangoFilterBackend]
    # 指定当前搜索条件
    search_fields = ["name", "price"]
    ordering = ["price"] #默认升序
    # ordering = ["-price"] # 前面加-号为降序
    # 如果想要阶梯式的显示的话,后面继续拼接值就行

    #指定分页器,不能使用列表,因为分页类型只能有一种
    # pagination_class = BasicsPagination

    filter_class=Compturefilter

